package com.example.shirotest.controller;

import com.example.shirotest.entry.User;
import org.apache.shiro.SecurityUtils;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.util.Set;

public class BashController {

    //配置一个Spring的异常监控，当工程抛出了value所指定的所以异常类型以后将直接进入到当前方法中
    @ExceptionHandler(value = {Exception.class})
    public String myError(Throwable throwable){
        //获取异常的类型，应该根据不同的异常类型进入到不通的页面显示不同提示信息
        System.out.println(throwable.getClass());
        System.out.println("---------------------------------");
        return "noPermission";
    }


    public void setUserInfo(Model model){
        User user = (User) SecurityUtils.getSubject().getPrincipal();

        model.addAttribute("userName",user.getName());
        model.addAttribute("userAccount",user.getAccount());
    }

}
